package com.saceem.ejb.timers;

import javax.ejb.ConcurrencyManagement;
import javax.ejb.ConcurrencyManagementType;
import javax.ejb.EJB;
import javax.ejb.Lock;
import javax.ejb.LockType;
import javax.ejb.Schedule;
import javax.ejb.Singleton;
import javax.ejb.Timeout;
import javax.ejb.Timer;

import org.apache.log4j.Logger;

import com.saceem.imagenes.logica.IProcesadorFactruas;

//@Stateless
@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER) // Esto hace que el contenedor maneje la concurrencia. 
//@Lock(LockType.READ) // allows timers to execute in parallel
public class EscanerService {

	private static final Logger log = Logger.getLogger(EscanerService.class
			.getName());
	
	@EJB
	IProcesadorFactruas procesador;

	/**
	 * Default constructor.
	 */
	public EscanerService() {
	}

	// Para correr cada determinados segundos poner esto second = "*/45", minute
	// ="*".
	@SuppressWarnings("unused")
	@Schedule(minute = "*/3", hour = "7-23", dayOfWeek = "Mon-Fri", dayOfMonth = "*", month = "*", year = "*", info = "EscanerTimerService")
	private void scheduledTask(final Timer t) {
		log.info("@ScheduledTask called at: " + new java.util.Date());
		procesador.procesar();
	}

	@SuppressWarnings("unused")
	@Timeout
	private void termino() {
		log.info("termino()");
	}
	
	

}
